/**********************************************************************************************/
/* VSQL_I_SqlDatabase.h                                                       				  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006															  */
/* All Rights Reserved                                                   					  */
/**********************************************************************************************/

#ifndef _VSQL_I_Database_h 
	#define _VSQL_I_Database_h
#pragma once

#include <VShared/VSQL/Headers/VSQL.h>

#include <VShared/FBL/publ/Interfaces/FBL_I_Database.h>
#include <VShared/FBL/publ/Interfaces/FBL_I_Value.h>

#include <VShared/FBL/publ/Interfaces/FBL_I_Connection.h>

#include <VShared/FBL/publ/Headers/FBL_pre_header.h>


/**********************************************************************************************/
VSQL_Begin_Namespace


/**********************************************************************************************/
SMART_INTERFACE(I_SqlDatabase);
SMART_INTERFACE(I_Cursor);

SMART_CLASS(QueryResult);

class SqlPlanPool;


/**********************************************************************************************/
// Provides functions to execute SQL queries for a Valentina database.
//
// Implementation of this interface should be a Database object  
// that is inherited from FBL::I_Database or that aggregates it. 
// Important is that user must be able obtain FBL::I_Database interface from object
// of SQL database.
//
//StubInterface
interface FBL_SHARED_EXP_CLASS I_SqlDatabase : public I_Unknown
{
	 	
virtual 					~I_SqlDatabase( void );

	// ---------------------
	// SQL methods:

							/** Executes SQL SELECT command for database.
								Returns Cursor as result of query.
								Throws VSQL::xException on error. */
virtual	I_Cursor_Ptr		SqlSelect( 
								const String& 		inQuery,								
								ECursorLocation 	inCursorLocation = kClient,
								ELockType 			inLockType = kReadOnly,
								ECursorDirection 	inCursorDirection = kForwardOnly,
								const ArrayOfValues_Ptr inBindings = NULL ) = 0;

							/** Executes any SQL command except SELECT.
								Returns the number of affected records.
								Throws VSQL::xException on error. */
virtual	ulong				SqlExecute( 
								const String&			inCommand,
								const ArrayOfValues_Ptr inBindings = NULL) = 0;
					
							/** SqlExecute with array of value arrays.  */
virtual	ulong				SqlExecute( 
									   const String&			inCommand,
									   const ArrayOfValueArrays_Ptr inBindings ) = 0;

							/** Executes any SQL command.
								Returns the object contained cursor or affected records'
								count depends on query matter.
								Throws VSQL::xException on error. */
virtual	QueryResult_Ptr		 SqlQuery(	
								const String& 			inQuery,								
								ECursorLocation 		inCursorLocation = kClient,
								ELockType 				inLockType = kReadOnly,
								ECursorDirection 		inCursorDirection = kForwardOnly,
								const ArrayOfValues_Ptr inBindings = NULL ) = 0;

	// ---------------------
	// Cursor methods:

							// returns the count of cursors for this db.
virtual ulong				get_CursorCount( void ) const throw() = 0;
								
virtual I_Cursor*			get_Cursor( ulong inIndex ) const throw() = 0;

							// Unregister the specified cursor.
							// Technically need to be here (Because VC_Cursor use it).
virtual	void				RemoveCursor( I_Cursor& inCursor ) = 0;


	// ---------------------
	// TEMPORARY, until we get QueryInterface().

virtual	FBL::I_Database_Ptr	get_BaseDatabase( void ) = 0;

}; 


/**********************************************************************************************/
VSQL_End_Namespace


/**********************************************************************************************/
#include <VShared/FBL/publ/Headers/FBL_post_header.h>


/**********************************************************************************************/
#endif // _VSQL_I_Database_h
